require 'md5'
class SrpointController < ApplicationController
 skip_before_filter
  def buy_point
    secret_key = "6b19357c2267cc221a3e013d01306267"
    sig = MD5.new(params[:id] +":"+ params[:new] +":"+ params[:uid] +":"+ secret_key).to_s

    result = 0
    if not PointHistory.exists?(["user_id = ? and action = ?",params[:uid],'srpoints total:' + params[:total]]) 
      PointHistory.create(:user_id=>params[:uid].to_i,:action=>'srpoints total:' + params[:total],:point=>params[:new].to_i,:earning => true,:related_user_id=>0)
      current_user = User.find(params[:uid])
      current_user.point = current_user.point + params[:new].to_i
      current_user.save
     if sig == params[:sig]
       result = 1
     else
       result = 0
     end
   end
   render :text=>result,:layout=>false
  end
  def adparlor
      PointHistory.create(:user_id=>params[:uid].to_i,:action=>'adparlar point:' + params[:credit],:point=>params[:credit].to_i,:earning => true,:related_user_id=>0)
      current_user = User.find(params[:uid])
      current_user.point = current_user.point + params[:credit].to_i
      current_user.save
     render :text=>'',:layout=>false
  end
end
